"""
Created on 18-Feb-2010

@author: dexen
"""

from wsgiref import simple_server
from pyamf.remoting.gateway.wsgi import WSGIGateway

import rpyc

from dexen.system.base.spec import DexenSpec
from dexen.system.server.info import UpdateManager


class FlexService:
    def echo(self, data):
        print "I am in Echo"
        return data; 
    
    def run_schema(self, spec):
        assert isinstance(spec, DexenSpec)
        spec = rpyc.classic.obtain(spec)
        #print "the len schema zip", len(spec.schema_zip), type(spec.schema_zip)
        update_mgr.run_master(spec)        

def main():
    global update_mgr
    
    update_mgr = UpdateManager()
    update_mgr.start()
    
    services = {
        'NodeManager':FlexService,
    }
    gw = WSGIGateway(services)
    
    httpd = simple_server.WSGIServer( ("172.20.34.116", 8000),
                                      simple_server.WSGIRequestHandler)  
    httpd.set_app(gw)
    print "Running Hello World AMF gateway on http://localhost:8000"
        
    try:
        httpd.serve_forever()
    except:
        print "I am in except haha "

if __name__ == "__main__":
    main()
